<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>centos7离线安装docker和docker-compose | Teler的日常</title>
    <meta name="generator" content="VuePress 1.9.9">
    <link rel="icon" href="/img/favicon.ico">
    <meta name="description" content="博客小站，记录我的学习日常和心情等">
    <meta name="keywords" content="前端博客,个人技术博客,前端,前端开发,前端框架,web前端,前端面试题,技术文档,学习,面试,JavaScript,js,ES6,TypeScript,vue,python,css3,html5,Node,git,github,markdown">
    <meta name="baidu-site-verification" content="code-Rpieelje4H">
    <meta name="theme-color" content="#11a8cd">
    
    <link rel="preload" href="/assets/css/0.styles.bb5b1957.css" as="style"><link rel="preload" href="/assets/js/app.d41d74c0.js" as="script"><link rel="preload" href="/assets/js/2.023436e0.js" as="script"><link rel="preload" href="/assets/js/79.7fc614fb.js" as="script"><link rel="prefetch" href="/assets/js/10.f3664957.js"><link rel="prefetch" href="/assets/js/100.98bebc7f.js"><link rel="prefetch" href="/assets/js/101.fe34203c.js"><link rel="prefetch" href="/assets/js/102.ff08e3d5.js"><link rel="prefetch" href="/assets/js/103.7f0f328d.js"><link rel="prefetch" href="/assets/js/104.cf87ee60.js"><link rel="prefetch" href="/assets/js/105.a87694e9.js"><link rel="prefetch" href="/assets/js/106.a478e8b1.js"><link rel="prefetch" href="/assets/js/107.720dff4e.js"><link rel="prefetch" href="/assets/js/108.27f0de33.js"><link rel="prefetch" href="/assets/js/109.f567acfb.js"><link rel="prefetch" href="/assets/js/11.f2e49a76.js"><link rel="prefetch" href="/assets/js/110.9763d4af.js"><link rel="prefetch" href="/assets/js/111.db6527e1.js"><link rel="prefetch" href="/assets/js/112.a20bf841.js"><link rel="prefetch" href="/assets/js/113.fffb90e0.js"><link rel="prefetch" href="/assets/js/114.e10b299e.js"><link rel="prefetch" href="/assets/js/115.73b68794.js"><link rel="prefetch" href="/assets/js/116.a41be574.js"><link rel="prefetch" href="/assets/js/117.f49ddfb7.js"><link rel="prefetch" href="/assets/js/118.f31c49c3.js"><link rel="prefetch" href="/assets/js/119.e7ddd80c.js"><link rel="prefetch" href="/assets/js/12.684abe5a.js"><link rel="prefetch" href="/assets/js/120.ab58a792.js"><link rel="prefetch" href="/assets/js/121.8070a099.js"><link rel="prefetch" href="/assets/js/122.bd4aa83d.js"><link rel="prefetch" href="/assets/js/123.8b28ab66.js"><link rel="prefetch" href="/assets/js/124.c64e8a82.js"><link rel="prefetch" href="/assets/js/125.8c37e25d.js"><link rel="prefetch" href="/assets/js/126.7a965ec1.js"><link rel="prefetch" href="/assets/js/127.15e3f4d7.js"><link rel="prefetch" href="/assets/js/128.92e24736.js"><link rel="prefetch" href="/assets/js/129.376be23d.js"><link rel="prefetch" href="/assets/js/13.f2551a14.js"><link rel="prefetch" href="/assets/js/130.cde8392a.js"><link rel="prefetch" href="/assets/js/131.f7e13266.js"><link rel="prefetch" href="/assets/js/132.a518186c.js"><link rel="prefetch" href="/assets/js/133.d4a43462.js"><link rel="prefetch" href="/assets/js/134.95f419b0.js"><link rel="prefetch" href="/assets/js/135.07df0368.js"><link rel="prefetch" href="/assets/js/136.08277af4.js"><link rel="prefetch" href="/assets/js/137.3c3b9976.js"><link rel="prefetch" href="/assets/js/138.1e1bb8ce.js"><link rel="prefetch" href="/assets/js/139.78d61366.js"><link rel="prefetch" href="/assets/js/14.4fac3ae1.js"><link rel="prefetch" href="/assets/js/15.c4e1a86c.js"><link rel="prefetch" href="/assets/js/16.08f9cfab.js"><link rel="prefetch" href="/assets/js/17.40f3d3ac.js"><link rel="prefetch" href="/assets/js/18.004165c1.js"><link rel="prefetch" href="/assets/js/19.71a91c37.js"><link rel="prefetch" href="/assets/js/20.be80e063.js"><link rel="prefetch" href="/assets/js/21.dd2e712d.js"><link rel="prefetch" href="/assets/js/22.efedd1da.js"><link rel="prefetch" href="/assets/js/23.b8d5f0c5.js"><link rel="prefetch" href="/assets/js/24.8895cb39.js"><link rel="prefetch" href="/assets/js/25.f72d16f6.js"><link rel="prefetch" href="/assets/js/26.700b8757.js"><link rel="prefetch" href="/assets/js/27.2d888c7a.js"><link rel="prefetch" href="/assets/js/28.c95a06e3.js"><link rel="prefetch" href="/assets/js/29.030c41dc.js"><link rel="prefetch" href="/assets/js/3.ae79ad07.js"><link rel="prefetch" href="/assets/js/30.024d7386.js"><link rel="prefetch" href="/assets/js/31.90222925.js"><link rel="prefetch" href="/assets/js/32.98d886f9.js"><link rel="prefetch" href="/assets/js/33.fdc186c5.js"><link rel="prefetch" href="/assets/js/34.c6364dc9.js"><link rel="prefetch" href="/assets/js/35.90745c1a.js"><link rel="prefetch" href="/assets/js/36.ad08862a.js"><link rel="prefetch" href="/assets/js/37.dec32d64.js"><link rel="prefetch" href="/assets/js/38.3838a6c1.js"><link rel="prefetch" href="/assets/js/39.f4e4d4db.js"><link rel="prefetch" href="/assets/js/4.92869e3b.js"><link rel="prefetch" href="/assets/js/40.5fd3bb13.js"><link rel="prefetch" href="/assets/js/41.51a8fdd5.js"><link rel="prefetch" href="/assets/js/42.82c2e073.js"><link rel="prefetch" href="/assets/js/43.f0ea2a9e.js"><link rel="prefetch" href="/assets/js/44.671c08a7.js"><link rel="prefetch" href="/assets/js/45.5d15b10b.js"><link rel="prefetch" href="/assets/js/46.95005641.js"><link rel="prefetch" href="/assets/js/47.c9ab5796.js"><link rel="prefetch" href="/assets/js/48.43986c57.js"><link rel="prefetch" href="/assets/js/49.08b41247.js"><link rel="prefetch" href="/assets/js/5.5e32f39e.js"><link rel="prefetch" href="/assets/js/50.c11a05b9.js"><link rel="prefetch" href="/assets/js/51.639c8ff2.js"><link rel="prefetch" href="/assets/js/52.df138aff.js"><link rel="prefetch" href="/assets/js/53.39e24743.js"><link rel="prefetch" href="/assets/js/54.f975b5ab.js"><link rel="prefetch" href="/assets/js/55.3ac72402.js"><link rel="prefetch" href="/assets/js/56.ed625cdd.js"><link rel="prefetch" href="/assets/js/57.65af0446.js"><link rel="prefetch" href="/assets/js/58.3468c7f0.js"><link rel="prefetch" href="/assets/js/59.fea7da2c.js"><link rel="prefetch" href="/assets/js/6.3caf43c7.js"><link rel="prefetch" href="/assets/js/60.b978be38.js"><link rel="prefetch" href="/assets/js/61.17791f1f.js"><link rel="prefetch" href="/assets/js/62.3cd7c7e2.js"><link rel="prefetch" href="/assets/js/63.941cd4c6.js"><link rel="prefetch" href="/assets/js/64.7d62a354.js"><link rel="prefetch" href="/assets/js/65.0f35ef90.js"><link rel="prefetch" href="/assets/js/66.c9cd517d.js"><link rel="prefetch" href="/assets/js/67.ed261888.js"><link rel="prefetch" href="/assets/js/68.ab36cb55.js"><link rel="prefetch" href="/assets/js/69.e43a29c4.js"><link rel="prefetch" href="/assets/js/7.49459967.js"><link rel="prefetch" href="/assets/js/70.9c465e47.js"><link rel="prefetch" href="/assets/js/71.10344edd.js"><link rel="prefetch" href="/assets/js/72.9b399737.js"><link rel="prefetch" href="/assets/js/73.11e18677.js"><link rel="prefetch" href="/assets/js/74.9ab52ddf.js"><link rel="prefetch" href="/assets/js/75.15e0a627.js"><link rel="prefetch" href="/assets/js/76.433e942f.js"><link rel="prefetch" href="/assets/js/77.6f9979c4.js"><link rel="prefetch" href="/assets/js/78.c2cb7a93.js"><link rel="prefetch" href="/assets/js/8.32c107dd.js"><link rel="prefetch" href="/assets/js/80.c75ae340.js"><link rel="prefetch" href="/assets/js/81.1d958700.js"><link rel="prefetch" href="/assets/js/82.9df67712.js"><link rel="prefetch" href="/assets/js/83.b3454e49.js"><link rel="prefetch" href="/assets/js/84.425e9e1a.js"><link rel="prefetch" href="/assets/js/85.d59ea930.js"><link rel="prefetch" href="/assets/js/86.4bdd04a1.js"><link rel="prefetch" href="/assets/js/87.121c124e.js"><link rel="prefetch" href="/assets/js/88.5a75898f.js"><link rel="prefetch" href="/assets/js/89.b87b375d.js"><link rel="prefetch" href="/assets/js/9.59e8ac2a.js"><link rel="prefetch" href="/assets/js/90.e51756a8.js"><link rel="prefetch" href="/assets/js/91.f8cae4b0.js"><link rel="prefetch" href="/assets/js/92.81b133ff.js"><link rel="prefetch" href="/assets/js/93.8350bd06.js"><link rel="prefetch" href="/assets/js/94.2d121b75.js"><link rel="prefetch" href="/assets/js/95.ef51b143.js"><link rel="prefetch" href="/assets/js/96.7d2163d3.js"><link rel="prefetch" href="/assets/js/97.a3cbbfc7.js"><link rel="prefetch" href="/assets/js/98.5ddb1d6b.js"><link rel="prefetch" href="/assets/js/99.5b21b4a2.js">
    <link rel="stylesheet" href="/assets/css/0.styles.bb5b1957.css">
  </head>
  <body class="theme-mode-light">
    <div id="app" data-server-rendered="true"><div class="theme-container have-rightmenu have-body-img"><header class="navbar blur"><div title="目录" class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="/img/logo.png" alt="Teler的日常" class="logo"> <span class="site-name can-hide">Teler的日常</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/" class="nav-link">首页</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="索引" class="dropdown-title"><a href="/archives/" class="link-title">索引</a> <span class="title" style="display:none;">索引</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/categories/" class="nav-link">分类</a></li><li class="dropdown-item"><!----> <a href="/tags/" class="nav-link">标签</a></li><li class="dropdown-item"><!----> <a href="/archives/" class="nav-link">归档</a></li></ul></div></div><div class="nav-item"><a href="/about/" class="nav-link">关于</a></div> <a href="https://github.com/fangweilong" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav></div></header> <div class="sidebar-mask"></div> <div class="sidebar-hover-trigger"></div> <aside class="sidebar" style="display:none;"><div class="blogger"><img src="/img/logo.png"> <div class="blogger-info"><h3>Teler</h3> <span>Day Day Up</span></div></div> <nav class="nav-links"><div class="nav-item"><a href="/" class="nav-link">首页</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="索引" class="dropdown-title"><a href="/archives/" class="link-title">索引</a> <span class="title" style="display:none;">索引</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/categories/" class="nav-link">分类</a></li><li class="dropdown-item"><!----> <a href="/tags/" class="nav-link">标签</a></li><li class="dropdown-item"><!----> <a href="/archives/" class="nav-link">归档</a></li></ul></div></div><div class="nav-item"><a href="/about/" class="nav-link">关于</a></div> <a href="https://github.com/fangweilong" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav>  <ul class="sidebar-links"><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>eclipse</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>idea</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>docker</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/pages/356b78/" class="sidebar-link">centos7-docker-更换迁移数据目录</a></li><li><a href="/pages/409adf/" aria-current="page" class="active sidebar-link">centos7离线安装docker和docker-compose</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level2"><a href="/pages/409adf/#实测版本说明" class="sidebar-link">实测版本说明</a></li><li class="sidebar-sub-header level2"><a href="/pages/409adf/#官方资源下载地址" class="sidebar-link">官方资源下载地址</a></li><li class="sidebar-sub-header level2"><a href="/pages/409adf/#上传到服务器" class="sidebar-link">上传到服务器</a></li><li class="sidebar-sub-header level2"><a href="/pages/409adf/#执行" class="sidebar-link">执行</a></li><li class="sidebar-sub-header level2"><a href="/pages/409adf/#install-sh" class="sidebar-link">install.sh</a></li><li class="sidebar-sub-header level2"><a href="/pages/409adf/#docker-service" class="sidebar-link">docker.service</a></li></ul></li><li><a href="/pages/6316d7/" class="sidebar-link">docker-hadoop伪分布式-java上传报错</a></li><li><a href="/pages/f7c364/" class="sidebar-link">java打包成docker-images</a></li></ul></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>navicat</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>nginx</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>tomcat</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>wsl</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>linux</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>网络</span> <span class="arrow right"></span></p> <!----></section></li></ul> </aside> <div><main class="page"><div class="theme-vdoing-wrapper bg-style-1"><div class="articleInfo-wrap" data-v-06225672><div class="articleInfo" data-v-06225672><ul class="breadcrumbs" data-v-06225672><li data-v-06225672><a href="/" title="首页" class="iconfont icon-home router-link-active" data-v-06225672></a></li> <li data-v-06225672><a href="/categories/?category=%E8%BF%90%E7%BB%B4%E3%80%81%E5%BC%80%E5%8F%91" title="分类" data-v-06225672>运维、开发</a></li><li data-v-06225672><a href="/categories/?category=docker" title="分类" data-v-06225672>docker</a></li></ul> <div class="info" data-v-06225672><div title="作者" class="author iconfont icon-touxiang" data-v-06225672><a href="https://github.com/fangweilong" target="_blank" title="作者" class="beLink" data-v-06225672>Teler</a></div> <div title="创建时间" class="date iconfont icon-riqi" data-v-06225672><a href="javascript:;" data-v-06225672>2020-02-02</a></div> <!----></div></div></div> <!----> <div class="content-wrapper"><div class="right-menu-wrapper"><div class="right-menu-margin"><div class="right-menu-title">目录</div> <div class="right-menu-content"></div></div></div> <h1><img src="">centos7离线安装docker和docker-compose<!----></h1>  <div class="theme-vdoing-content content__default"><h2 id="实测版本说明"><a href="#实测版本说明" class="header-anchor">#</a> 实测版本说明</h2> <div class="language- extra-class"><pre><code>centos：7.5
docker：19.03.5
docker-compose：1.24.3
</code></pre></div><h2 id="官方资源下载地址"><a href="#官方资源下载地址" class="header-anchor">#</a> 官方资源下载地址</h2> <div class="language- extra-class"><pre><code>自行下载需要的版本。
[docker](https://download.docker.com/linux/static/stable/x86_64/)
[docker-compose](https://github.com/docker/compose/releases)
</code></pre></div><h2 id="上传到服务器"><a href="#上传到服务器" class="header-anchor">#</a> 上传到服务器</h2> <div class="language- extra-class"><pre><code>上传 install-docker-offline.sh docker.service docker-ce docker-compose-Linux-x86_64压缩包到任意的同一文件夹下  
建议到/home
</code></pre></div><h2 id="执行"><a href="#执行" class="header-anchor">#</a> 执行</h2> <div class="language- extra-class"><pre><code>sh install-docker-offline.sh

其他的根据脚本提示操作
</code></pre></div><h2 id="install-sh"><a href="#install-sh" class="header-anchor">#</a> install.sh</h2> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token shebang important">#!/bin/sh</span>
<span class="token builtin class-name">echo</span> <span class="token parameter variable">-e</span> <span class="token string">'作者：Teler'</span>
<span class="token builtin class-name">echo</span> <span class="token parameter variable">-e</span> <span class="token string">'版本：v0.0.1'</span>
<span class="token builtin class-name">echo</span> <span class="token parameter variable">-e</span> <span class="token string">'创建时间:2020-02-02'</span>
<span class="token builtin class-name">echo</span> <span class="token parameter variable">-e</span> <span class="token string">'更新时间:2020-02-02 22:21'</span>

<span class="token builtin class-name">echo</span> <span class="token parameter variable">-e</span> <span class="token string">'给自己赋权限\n'</span>
<span class="token function">chmod</span> +x ./<span class="token variable">$0</span>

<span class="token comment">#初始化</span>
<span class="token keyword">function</span> <span class="token function-name function">init</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token function">clear</span>
    <span class="token builtin class-name">echo</span> <span class="token parameter variable">-e</span> <span class="token string">'请选择操作\n'</span>
    <span class="token builtin class-name">echo</span> <span class="token parameter variable">-e</span> <span class="token string">'1.安装docker\n'</span>
    <span class="token builtin class-name">echo</span> <span class="token parameter variable">-e</span> <span class="token string">'2.安装docker-compose\n'</span>
    <span class="token builtin class-name">echo</span> <span class="token parameter variable">-e</span> <span class="token string">'exit:退出'</span>
    
    call
<span class="token punctuation">}</span> 

<span class="token comment">#决定调用什么方法</span>
<span class="token keyword">function</span> <span class="token function-name function">call</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token builtin class-name">echo</span> <span class="token parameter variable">-e</span> <span class="token string">'\n'</span>
    <span class="token builtin class-name">read</span> <span class="token parameter variable">-p</span> <span class="token string">'请输入:'</span> INPUT
    <span class="token keyword">case</span> <span class="token variable">$INPUT</span> <span class="token keyword">in</span>
        <span class="token number">1</span><span class="token punctuation">)</span>
        installDocker
        <span class="token punctuation">;</span><span class="token punctuation">;</span>
        <span class="token number">2</span><span class="token punctuation">)</span>
        installDockerCompose
        <span class="token punctuation">;</span><span class="token punctuation">;</span>
               
        *<span class="token punctuation">)</span>
        <span class="token comment">#noFound</span>
        <span class="token builtin class-name">echo</span> <span class="token string">'感谢使用........'</span>
        <span class="token builtin class-name">exit</span>
        <span class="token punctuation">;</span><span class="token punctuation">;</span>
    <span class="token keyword">esac</span>

    <span class="token keyword">if</span> <span class="token punctuation">[</span> <span class="token variable">$?</span> <span class="token parameter variable">-eq</span> <span class="token number">0</span> <span class="token punctuation">]</span><span class="token punctuation">;</span><span class="token keyword">then</span>
        init
    <span class="token keyword">fi</span> 
<span class="token punctuation">}</span>

<span class="token comment">#安装docker</span>
<span class="token keyword">function</span> <span class="token function-name function">installDocker</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token builtin class-name">read</span> <span class="token parameter variable">-p</span> <span class="token string">'请输入完整的docker压缩包文件名:'</span> FILENAME

    searchFile <span class="token variable">$FILENAME</span>

    <span class="token keyword">if</span> <span class="token punctuation">[</span> <span class="token variable">$?</span> <span class="token parameter variable">-ne</span> <span class="token number">0</span> <span class="token punctuation">]</span><span class="token punctuation">;</span><span class="token keyword">then</span>
        <span class="token builtin class-name">echo</span> <span class="token parameter variable">-e</span> <span class="token string">'\n文件不存在'</span>
        installDocker
    <span class="token keyword">fi</span>

    <span class="token builtin class-name">echo</span> <span class="token parameter variable">-e</span> <span class="token string">'\n解压文件...'</span>
    <span class="token function">tar</span> <span class="token parameter variable">-xzvf</span> <span class="token variable">$FILENAME</span>
    <span class="token keyword">if</span> <span class="token punctuation">[</span> <span class="token variable">$?</span> <span class="token parameter variable">-eq</span> <span class="token number">0</span> <span class="token punctuation">]</span><span class="token punctuation">;</span><span class="token keyword">then</span>
        <span class="token builtin class-name">echo</span> <span class="token parameter variable">-e</span> <span class="token string">'\n将docker目录移到/usr/bin目录下...'</span>
        <span class="token function">cp</span> docker/* /usr/bin/
        <span class="token keyword">if</span> <span class="token punctuation">[</span> <span class="token variable">$?</span> <span class="token parameter variable">-ne</span> <span class="token number">0</span> <span class="token punctuation">]</span><span class="token punctuation">;</span><span class="token keyword">then</span>
            <span class="token builtin class-name">echo</span> <span class="token parameter variable">-e</span> <span class="token string">'\n复制失败'</span>
            <span class="token builtin class-name">exit</span>
        <span class="token keyword">fi</span>
        <span class="token builtin class-name">echo</span> <span class="token parameter variable">-e</span> <span class="token string">'\n将docker.service 移到/etc/systemd/system/ 目录...'</span>
        <span class="token function">cp</span> docker.service /etc/systemd/system/
        <span class="token keyword">if</span> <span class="token punctuation">[</span> <span class="token variable">$?</span> <span class="token parameter variable">-eq</span> <span class="token number">0</span> <span class="token punctuation">]</span><span class="token punctuation">;</span><span class="token keyword">then</span>
            <span class="token builtin class-name">echo</span> <span class="token parameter variable">-e</span> <span class="token string">'\n添加文件权限...'</span>
            <span class="token function">chmod</span> +x /etc/systemd/system/docker.service
            <span class="token keyword">if</span> <span class="token punctuation">[</span> <span class="token variable">$?</span> <span class="token parameter variable">-ne</span> <span class="token number">0</span> <span class="token punctuation">]</span><span class="token punctuation">;</span><span class="token keyword">then</span>
                <span class="token builtin class-name">echo</span> <span class="token parameter variable">-e</span> <span class="token string">'\n添加失败'</span>
                <span class="token builtin class-name">exit</span>
            <span class="token keyword">fi</span>
            <span class="token builtin class-name">echo</span> <span class="token parameter variable">-e</span> <span class="token string">'\n重新加载配置文件...'</span>
            systemctl daemon-reload
            <span class="token keyword">if</span> <span class="token punctuation">[</span> <span class="token variable">$?</span> <span class="token parameter variable">-ne</span> <span class="token number">0</span> <span class="token punctuation">]</span><span class="token punctuation">;</span><span class="token keyword">then</span>
                <span class="token builtin class-name">echo</span> <span class="token parameter variable">-e</span> <span class="token string">'\n加载失败'</span>
                <span class="token builtin class-name">exit</span>
            <span class="token keyword">fi</span>
            <span class="token builtin class-name">echo</span> <span class="token parameter variable">-e</span> <span class="token string">'\n启动docker...'</span>
            systemctl start <span class="token function">docker</span>
            <span class="token keyword">if</span> <span class="token punctuation">[</span> <span class="token variable">$?</span> <span class="token parameter variable">-ne</span> <span class="token number">0</span> <span class="token punctuation">]</span><span class="token punctuation">;</span><span class="token keyword">then</span>
                <span class="token builtin class-name">echo</span> <span class="token parameter variable">-e</span> <span class="token string">'\n启动失败'</span>
                <span class="token builtin class-name">exit</span>
            <span class="token keyword">fi</span>
            <span class="token builtin class-name">echo</span> <span class="token parameter variable">-e</span> <span class="token string">'\n设置开机自启...'</span>
            systemctl <span class="token builtin class-name">enable</span> docker.service
            <span class="token keyword">if</span> <span class="token punctuation">[</span> <span class="token variable">$?</span> <span class="token parameter variable">-ne</span> <span class="token number">0</span> <span class="token punctuation">]</span><span class="token punctuation">;</span><span class="token keyword">then</span>
                <span class="token builtin class-name">echo</span> <span class="token parameter variable">-e</span> <span class="token string">'\n开机启动失败'</span>
                <span class="token builtin class-name">exit</span>
            <span class="token keyword">fi</span>
            <span class="token builtin class-name">echo</span> <span class="token parameter variable">-e</span> <span class="token string">'\ndocker版本：'</span>
            <span class="token function">docker</span> <span class="token parameter variable">-v</span>
        <span class="token keyword">else</span>
            <span class="token builtin class-name">echo</span> <span class="token parameter variable">-e</span> <span class="token string">'\n复制失败'</span>
            <span class="token builtin class-name">exit</span>
        <span class="token keyword">fi</span>
    <span class="token keyword">else</span>
        <span class="token builtin class-name">echo</span> <span class="token parameter variable">-e</span> <span class="token string">'\n解压失败'</span>
        <span class="token builtin class-name">exit</span>    
    <span class="token keyword">fi</span>
    <span class="token builtin class-name">return</span> <span class="token number">0</span>
<span class="token punctuation">}</span>
<span class="token comment">#安装docker-compose</span>
<span class="token keyword">function</span> <span class="token function-name function">installDockerCompose</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token builtin class-name">read</span> <span class="token parameter variable">-p</span> <span class="token string">'请输入完整的docker compose文件名:'</span> FILENAME

    searchFile <span class="token variable">$FILENAME</span>

    <span class="token keyword">if</span> <span class="token punctuation">[</span> <span class="token variable">$?</span> <span class="token parameter variable">-ne</span> <span class="token number">0</span> <span class="token punctuation">]</span><span class="token punctuation">;</span><span class="token keyword">then</span>
        <span class="token builtin class-name">echo</span> <span class="token parameter variable">-e</span> <span class="token string">'\n文件不存在'</span>
        installDockerCompose
    <span class="token keyword">fi</span>

    <span class="token builtin class-name">echo</span> <span class="token parameter variable">-e</span> <span class="token string">'\n复制文件到/usr/local/bin下 并重命名为docker-compose'</span>
    <span class="token function">cp</span> <span class="token parameter variable">-y</span> <span class="token variable">$FILENAME</span> /usr/local/bin/docker-compose
    <span class="token keyword">if</span> <span class="token punctuation">[</span> <span class="token variable">$?</span> <span class="token parameter variable">-ne</span> <span class="token number">0</span> <span class="token punctuation">]</span><span class="token punctuation">;</span><span class="token keyword">then</span>
        <span class="token builtin class-name">echo</span> <span class="token parameter variable">-e</span> <span class="token string">'\n赋予执行权限'</span>
        <span class="token function">chmod</span> +x /usr/local/bin/docker-compose

        <span class="token builtin class-name">echo</span> <span class="token string">'\ndocker-compose版本：'</span>
        <span class="token function">docker-compose</span> <span class="token parameter variable">-v</span>
    <span class="token keyword">else</span> 
        <span class="token builtin class-name">echo</span> <span class="token string">'\n复制失败'</span>
    <span class="token keyword">fi</span>


    <span class="token builtin class-name">return</span> <span class="token number">0</span>
<span class="token punctuation">}</span>

<span class="token comment">#暂未支持</span>
<span class="token keyword">function</span> <span class="token function-name function">noFound</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token builtin class-name">echo</span> <span class="token parameter variable">-e</span> <span class="token string">'暂未支持'</span>
    <span class="token builtin class-name">return</span> <span class="token number">0</span>
<span class="token punctuation">}</span>

<span class="token comment">#检查文件是否存在</span>
<span class="token comment">#存在返回0 不存在返回1</span>
<span class="token keyword">function</span> <span class="token function-name function">searchFile</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token keyword">if</span> <span class="token punctuation">[</span> <span class="token parameter variable">-f</span> <span class="token string">&quot;<span class="token variable">$1</span>&quot;</span> <span class="token punctuation">]</span><span class="token punctuation">;</span> <span class="token keyword">then</span>
        <span class="token builtin class-name">return</span> <span class="token number">0</span>
    <span class="token keyword">else</span> 
        <span class="token builtin class-name">return</span> <span class="token number">1</span>
    <span class="token keyword">fi</span>
<span class="token punctuation">}</span>




init


</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br><span class="line-number">39</span><br><span class="line-number">40</span><br><span class="line-number">41</span><br><span class="line-number">42</span><br><span class="line-number">43</span><br><span class="line-number">44</span><br><span class="line-number">45</span><br><span class="line-number">46</span><br><span class="line-number">47</span><br><span class="line-number">48</span><br><span class="line-number">49</span><br><span class="line-number">50</span><br><span class="line-number">51</span><br><span class="line-number">52</span><br><span class="line-number">53</span><br><span class="line-number">54</span><br><span class="line-number">55</span><br><span class="line-number">56</span><br><span class="line-number">57</span><br><span class="line-number">58</span><br><span class="line-number">59</span><br><span class="line-number">60</span><br><span class="line-number">61</span><br><span class="line-number">62</span><br><span class="line-number">63</span><br><span class="line-number">64</span><br><span class="line-number">65</span><br><span class="line-number">66</span><br><span class="line-number">67</span><br><span class="line-number">68</span><br><span class="line-number">69</span><br><span class="line-number">70</span><br><span class="line-number">71</span><br><span class="line-number">72</span><br><span class="line-number">73</span><br><span class="line-number">74</span><br><span class="line-number">75</span><br><span class="line-number">76</span><br><span class="line-number">77</span><br><span class="line-number">78</span><br><span class="line-number">79</span><br><span class="line-number">80</span><br><span class="line-number">81</span><br><span class="line-number">82</span><br><span class="line-number">83</span><br><span class="line-number">84</span><br><span class="line-number">85</span><br><span class="line-number">86</span><br><span class="line-number">87</span><br><span class="line-number">88</span><br><span class="line-number">89</span><br><span class="line-number">90</span><br><span class="line-number">91</span><br><span class="line-number">92</span><br><span class="line-number">93</span><br><span class="line-number">94</span><br><span class="line-number">95</span><br><span class="line-number">96</span><br><span class="line-number">97</span><br><span class="line-number">98</span><br><span class="line-number">99</span><br><span class="line-number">100</span><br><span class="line-number">101</span><br><span class="line-number">102</span><br><span class="line-number">103</span><br><span class="line-number">104</span><br><span class="line-number">105</span><br><span class="line-number">106</span><br><span class="line-number">107</span><br><span class="line-number">108</span><br><span class="line-number">109</span><br><span class="line-number">110</span><br><span class="line-number">111</span><br><span class="line-number">112</span><br><span class="line-number">113</span><br><span class="line-number">114</span><br><span class="line-number">115</span><br><span class="line-number">116</span><br><span class="line-number">117</span><br><span class="line-number">118</span><br><span class="line-number">119</span><br><span class="line-number">120</span><br><span class="line-number">121</span><br><span class="line-number">122</span><br><span class="line-number">123</span><br><span class="line-number">124</span><br><span class="line-number">125</span><br><span class="line-number">126</span><br><span class="line-number">127</span><br><span class="line-number">128</span><br><span class="line-number">129</span><br><span class="line-number">130</span><br><span class="line-number">131</span><br><span class="line-number">132</span><br><span class="line-number">133</span><br><span class="line-number">134</span><br><span class="line-number">135</span><br><span class="line-number">136</span><br><span class="line-number">137</span><br><span class="line-number">138</span><br><span class="line-number">139</span><br><span class="line-number">140</span><br><span class="line-number">141</span><br><span class="line-number">142</span><br><span class="line-number">143</span><br><span class="line-number">144</span><br><span class="line-number">145</span><br><span class="line-number">146</span><br><span class="line-number">147</span><br><span class="line-number">148</span><br><span class="line-number">149</span><br><span class="line-number">150</span><br><span class="line-number">151</span><br><span class="line-number">152</span><br></div></div><h2 id="docker-service"><a href="#docker-service" class="header-anchor">#</a> docker.service</h2> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token punctuation">[</span>Unit<span class="token punctuation">]</span>
<span class="token assign-left variable">Description</span><span class="token operator">=</span>Docker Application Container Engine
<span class="token assign-left variable">Documentation</span><span class="token operator">=</span>https://docs.docker.com
<span class="token assign-left variable">After</span><span class="token operator">=</span>network-online.target firewalld.service
<span class="token assign-left variable">Wants</span><span class="token operator">=</span>network-online.target
 
<span class="token punctuation">[</span>Service<span class="token punctuation">]</span>
<span class="token assign-left variable">Type</span><span class="token operator">=</span>notify
<span class="token comment"># the default is not to use systemd for cgroups because the delegate issues still</span>
<span class="token comment"># exists and systemd currently does not support the cgroup feature set required</span>
<span class="token comment"># for containers run by docker</span>
<span class="token assign-left variable">ExecStart</span><span class="token operator">=</span>/usr/bin/dockerd
<span class="token assign-left variable">ExecReload</span><span class="token operator">=</span>/bin/kill <span class="token parameter variable">-s</span> HUP <span class="token variable">$MAINPID</span>
<span class="token comment"># Having non-zero Limit*s causes performance problems due to accounting overhead</span>
<span class="token comment"># in the kernel. We recommend using cgroups to do container-local accounting.</span>
<span class="token assign-left variable">LimitNOFILE</span><span class="token operator">=</span>infinity
<span class="token assign-left variable">LimitNPROC</span><span class="token operator">=</span>infinity
<span class="token assign-left variable">LimitCORE</span><span class="token operator">=</span>infinity
<span class="token comment"># Uncomment TasksMax if your systemd version supports it.</span>
<span class="token comment"># Only systemd 226 and above support this version.</span>
<span class="token comment">#TasksMax=infinity</span>
<span class="token assign-left variable">TimeoutStartSec</span><span class="token operator">=</span><span class="token number">0</span>
<span class="token comment"># set delegate yes so that systemd does not reset the cgroups of docker containers</span>
<span class="token assign-left variable">Delegate</span><span class="token operator">=</span>yes
<span class="token comment"># kill only the docker process, not all processes in the cgroup</span>
<span class="token assign-left variable">KillMode</span><span class="token operator">=</span>process
<span class="token comment"># restart the docker process if it exits prematurely</span>
<span class="token assign-left variable">Restart</span><span class="token operator">=</span>on-failure
<span class="token assign-left variable">StartLimitBurst</span><span class="token operator">=</span><span class="token number">3</span>
<span class="token assign-left variable">StartLimitInterval</span><span class="token operator">=</span>60s
 
<span class="token punctuation">[</span>Install<span class="token punctuation">]</span>
<span class="token assign-left variable">WantedBy</span><span class="token operator">=</span>multi-user.target
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br></div></div></div></div>  <div class="page-edit"><div class="edit-link"><a href="https://github.com/fangweilong/edit/master/docs/03.运维、开发/03.docker/02.centos7离线安装docker和docker-compose.md" target="_blank" rel="noopener noreferrer">编辑</a> <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></div> <div class="tags"><a href="/tags/?tag=docker" title="标签">#docker</a><a href="/tags/?tag=docker-compose" title="标签">#docker-compose</a></div> <div class="last-updated"><span class="prefix">上次更新:</span> <span class="time">2024-12-06, 10:03:39</span></div></div> <div class="page-nav-wapper"><div class="page-nav-centre-wrap"><a href="/pages/356b78/" class="page-nav-centre page-nav-centre-prev"><div class="tooltip">centos7-docker-更换迁移数据目录</div></a> <a href="/pages/6316d7/" class="page-nav-centre page-nav-centre-next"><div class="tooltip">docker-hadoop伪分布式-java上传报错</div></a></div> <div class="page-nav"><p class="inner"><span class="prev">
        ←
        <a href="/pages/356b78/" class="prev">centos7-docker-更换迁移数据目录</a></span> <span class="next"><a href="/pages/6316d7/">docker-hadoop伪分布式-java上传报错</a>→
      </span></p></div></div></div> <div class="article-list"><div class="article-title"><a href="/archives" class="iconfont icon-bi">最近更新</a></div> <div class="article-wrapper"><dl><dd>01</dd> <dt><a href="/pages/4ab140/"><div>
            利用cf大善人的 pages+AI gateway 搭建自己的AI平台
            <!----></div></a> <span class="date">12-06</span></dt></dl><dl><dd>02</dd> <dt><a href="/pages/104183/"><div>
            java playwright爬虫
            <!----></div></a> <span class="date">11-06</span></dt></dl><dl><dd>03</dd> <dt><a href="/pages/bdcbb5/"><div>
            连接chrome调试
            <!----></div></a> <span class="date">07-23</span></dt></dl> <dl><dd></dd> <dt><a href="/archives" class="more">更多文章&gt;</a></dt></dl></div></div></main></div> <div class="footer"><div class="icons"><a href="fangweilong@outlook.com" title="发邮件" target="_blank" class="iconfont icon-youjian"></a><a href="https://github.com/fangweilong" title="GitHub" target="_blank" class="iconfont icon-github"></a></div> 
  Theme by
  <a href="https://github.com/xugaoyi/vuepress-theme-vdoing" target="_blank" title="本站主题">Vdoing</a> 
    | Copyright © 2021-2024
    <span> Teler 版权所有 | 我的博客小站。欢迎评论OR转发！</span></div> <div class="buttons"><div title="返回顶部" class="button blur go-to-top iconfont icon-fanhuidingbu" style="display:none;"></div> <div title="去评论" class="button blur go-to-comment iconfont icon-pinglun" style="display:none;"></div> <div title="主题模式" class="button blur theme-mode-but iconfont icon-zhuti"><ul class="select-box" style="display:none;"><li class="iconfont icon-zidong">
          跟随系统
        </li><li class="iconfont icon-rijianmoshi">
          浅色模式
        </li><li class="iconfont icon-yejianmoshi">
          深色模式
        </li><li class="iconfont icon-yuedu">
          阅读模式
        </li></ul></div></div> <div class="body-bg" style="background:url() center center / cover no-repeat;opacity:0.5;"></div> <!----> <!----></div><div class="global-ui"><div></div><canvas id="vuepress-canvas-cursor"></canvas><div></div></div></div>
    <script src="/assets/js/app.d41d74c0.js" defer></script><script src="/assets/js/2.023436e0.js" defer></script><script src="/assets/js/79.7fc614fb.js" defer></script>
  </body>
</html>
